package com.iot.service.controller;

import com.iot.service.mqtt.model.request.TlMqttPubRelReq;
import com.iot.service.mqtt.model.request.TlMqttPublishReq;
import com.iot.service.mqtt.service.pub.IPublishStoreService;
import com.iot.service.mqtt.service.rel.IPubrelStoreService;
import com.iot.service.mqtt.service.session.ISessionService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

/**
 * @Author: hszhou
 * @Date: 2025/1/23 9:09
 * @Description: 必须描述类做什么事情, 实现什么功能
 */
@RestController
@RequestMapping("mqtt")
@RequiredArgsConstructor
public class MqttController {


    private final ISessionService mqttSessionService;

    private final IPublishStoreService mqttPublishStoreService;

    private final IPubrelStoreService pubrelStoreService;

    /**
     * @description: 获取所有的客户端数量
     * @author: hszhou
     * @datetime: 2025-05-08 15:23:27
     * @param:
     * @return: Mono<Long>
     **/
    @GetMapping("clients")
    public Mono<Long> getClients() {
        return mqttSessionService.clients().count();
    }


    @GetMapping("pub/{clientId}")
    public Flux<TlMqttPublishReq> getPubStore(@PathVariable("clientId")String clientId) {
        return mqttPublishStoreService.findPublishMessage(clientId);
    }

    @GetMapping("rel/{clientId}")
    public Flux<TlMqttPubRelReq> getPubRel(@PathVariable("clientId")String clientId) {
        return pubrelStoreService.findPubRelMessage(clientId);
    }

}
